package nyist.media.entity;

import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.builder.CompareToBuilder;

import javax.persistence.MappedSuperclass;
import javax.validation.constraints.Min;

/**
 * 排序基类
 *
 * @author dcf
 */
@Getter
@Setter
@MappedSuperclass
public abstract class OrderBaseEntity extends BaseEntity implements Comparable<OrderBaseEntity> {
    private static final long serialVersionUID = -4955356803162497727L;

    /**
     * "ID"属性名称
     */
    public static final String ID_PROPERTY_NAME = "id";

    /**
     * "创建日期"属性名称
     */
    public static final String CREATE_DATE_PROPERTY_NAME = "createDate";

    /**
     * "修改日期"属性名称
     */
    public static final String MODIFY_DATE_PROPERTY_NAME = "modifyDate";

    /**
     * "版本"属性名称
     */
    public static final String VERSION_PROPERTY_NAME = "version";


    /** "排序"属性名称 */
    public static final String ORDER_PROPERTY_NAME = "orders";


    /**
     * 排序
     */
    @Min(0)
    private Integer orders;

    /**
     * 实现compareTo方法
     *
     * @param orderEntity 排序对象
     * @return 比较结果
     */
    @Override
    public int compareTo(OrderBaseEntity orderEntity) {
        return new CompareToBuilder().append(getOrders(), orderEntity.getOrders()).append(getId(), orderEntity.getId()).toComparison();
    }
}
